package com.company.笔试.科大讯飞笔试;

import java.util.Scanner;

public class Main1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String n = sc.nextLine();
        String[] s = n.split(" ");
        int N = Integer.parseInt(s[0]);
        int K = Integer.parseInt(s[1]);
        int[] local = new int[K];
        int res = 0;//X
        for(int i = 0; i < K; i++){
            String ss = sc.nextLine();
            String[] l = ss.split(" ");
            int from = Integer.parseInt(l[0]);
            int to = Integer.parseInt(l[1]);
            if (from==res) res = to;
            else if (to==res)res=from;
        }
        System.out.println(res);



    }
}